package com.lianrui.app.goods.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.lianrui.app.goods.dao.IGoodsDao;
import com.lianrui.app.goods.domain.Goods;
import com.lianrui.app.goods.service.IGoodsService;
import com.lianrui.app.goods.vos.GoodsPage;
import com.lianrui.commons.exception.BusinessException;
import com.lianrui.core.AbstractService;
import com.lianrui.core.IDao;

/**
 * 功能描述：商品服务实现类
 *
 * @author LJQ
 *
 *         2016年1月5日 上午10:27:49
 */
@Service("goodsService")
public class GoodsService extends AbstractService<GoodsPage, Goods, Integer>
        implements IGoodsService {

    private static final Logger LOGGER = LoggerFactory
            .getLogger(GoodsService.class);

    @Resource
    IGoodsDao goodsDao;

    private static final long serialVersionUID = 1L;

    @Override
    public IDao<GoodsPage, Goods, Integer> getDao() throws BusinessException {
        return goodsDao;
    }

    @Override
    protected Logger getLogger() {
        return LOGGER;
    }

    @Override
    public List<Goods> recommendGoods(int num) throws BusinessException {
        return this.goodsDao.recommendGoods(num);
    }

    @Override
    public int getOrderItemCount(Integer orderId) {

        return goodsDao.getOrderItemCount(orderId);
    }

    /**
     * 
     * @Title: unique
     * @Description: 添加图片地址转换
     * @param id
     * @return
     * @throws BusinessException
     * @see com.lianrui.core.AbstractService#unique(java.lang.Object)
     */
    @Override
    public Goods unique(Integer id) throws BusinessException {
        Goods goods = super.unique(id);
        String image_default = goods.getImage_default();
        image_default = image_default.replaceAll("fs:",
                "http://www.lianrui.com/statics");
        goods.setImage_default(image_default);

        String image_file = goods.getImage_file();
        image_file = image_file.replaceAll("fs:",
                "http://www.lianrui.com/statics");
        goods.setImage_file(image_file);

        return goods;
    }

}
